package online.longzipeng.mywebdemo;

import cn.hutool.core.collection.CollUtil;
import lombok.extern.slf4j.Slf4j;
import online.longzipeng.mywebdemo.entity.User;
import online.longzipeng.mywebdemo.mapper.UserMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

/**
 * @author lzp
 * @Date:2022/11/14
 * @description:
 */
@Slf4j
@SpringBootTest(classes = MyWebDemoApplication.class,
		// 配置端口启动，否则获取失败
		webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class BatchUpdateDemo {

	@Autowired
	private UserMapper userMapper;

	@Test
	public void updateBatchTest() {
		List<User> users = CollUtil.newArrayList(
				User.builder().id(1).age(20).sex(1).build(),
				User.builder().id(2).age(55).sex(2).build(),
				User.builder().id(3).age(88).sex(1).build(),
				User.builder().id(4).age(25).sex(2).build(),
				User.builder().id(5).age(12).sex(1).build(),
				User.builder().id(6).age(11).sex(2).build()
		);
//		userMapper.updateBatchByWhenCase(users);
		userMapper.updateBatchByInsert(users);
	}

}
